<?php defined('SYSPATH') or die('No direct script access.');
/**
 * 用于编辑器文件上传
 *
 * @author  Yellow.Chow <aultoale@gmail.com>
 * @version $Id: editor.php 189 2012-05-04 09:56:51Z yellow.chow $
 * @license http://www.gnu.org/licenses/gpl-3.0.html    GPL 3
 */
class Upload_Editor extends Upload_Rename
{

    /**
     * 设置参数
     *
     * @param  string  $path
     * @param  string  $file
     * @return string
     * @throws Upload_Exception
     */
    public function save($path, $file)
    {
        $savefile = date('/Ym/').str_replace('.', '', microtime(TRUE)).'.'.$this->get_ext($file);
        $newfile = IO::strip($path.$savefile);

        // if (file_exists($newfile))
        // {
        //     throw new Upload_Exception('同名的文件已经存在，请将文件重命名后再执行上传');
        // }

        $path = dirname($newfile);
        if ( ! IO::mkdir($path)) // 创建目录
        {
            throw new Upload_Exception('无法创建文件上传目录 ":path"',
                array(':path' => Debug::path($path)));
        }

        if ( ! @move_uploaded_file($this->_tmp, $newfile))
        {
            throw new Upload_Exception('无法从临时目录复制上传文件');
        }

        return $savefile;
    }

}